import 'dart:convert';
import 'dart:io';

import 'dart:typed_data';

import 'package:path_provider/path_provider.dart';

extension FileUtils on File {
  Future<String> toBase64String() async => base64Encode(await readAsBytes());
}

class FileUtil {
  static Future<String> createFileFromString(String base64Str) async {
    Uint8List bytes = base64.decode(base64Str.split('base64,').last);
    String dir = (await getApplicationDocumentsDirectory()).path;
    File file = File("$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + ".png");
    await file.writeAsBytes(bytes);
    return file.path;
  }
}
